package life.ks98.community.controller;

import life.ks98.community.dto.PaginationDTO;
import life.ks98.community.dto.QuestionDTO;
import life.ks98.community.mapper.UserMapper;
import life.ks98.community.model.Question;
import life.ks98.community.model.User;
import life.ks98.community.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Kyrie
 * @date 2021/2/10 - 13:35
 */
@Controller
public class IndexController {

    @Autowired
    private QuestionService questionService;

    /**
     * 跳转主页
     */
    @RequestMapping("/")
    public String index(
            HttpServletRequest request,
            Model model,
            @RequestParam(name = "page", defaultValue = "1") Integer page,
            @RequestParam(name = "size", defaultValue = "10") Integer size,
            @RequestParam(name = "search", required = false) String search) {
        // 获取列表文章信息
        PaginationDTO<QuestionDTO> pagination = questionService.list(search,page, size);
        model.addAttribute("pagination", pagination);
        model.addAttribute("search", search);
        return "index";
    }
}
